/* 
    Copyright (c) 2011 Microsoft Corporation.  All rights reserved.
    Use of this sample source code is subject to the terms of the Microsoft license 
    agreement under which you licensed this sample source code and is provided AS-IS.
    If you did not accept the terms of the license agreement, you are not authorized 
    to use this sample source code.  For the terms of the license, please see the 
    license agreement between you and Microsoft.
  
    To see all Code Samples for Windows Phone, visit http://go.microsoft.com/fwlink/?LinkID=219604 
  
*/
using System;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Tasks;
using TagCloudNewsLibrary;
using TagCloudNewsLibrary.Model;

namespace TagCloudNews
{
    public partial class ViewerPage : PhoneApplicationPage
    {
        // Constructor
        public ViewerPage()
        {
            InitializeComponent();
        }

        // This method determines whether the user has navigated to the application after the application was tombstoned.
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            object title;

            if (PhoneApplicationService.Current.State.TryGetValue("title", out title)) 
            { 
                TagDataService.Current.ReadStory(title as string);
                DataContext = TagDataService.Current.GetViewerForStory(title as string);
            }
        }

        private void ShareButton_Click(object sender, EventArgs e)
        {
            ShareLinkTask shareLinkTask = new ShareLinkTask();

            ViewerModel v=DataContext as ViewerModel;

            shareLinkTask.Title =v.Title;
            shareLinkTask.LinkUri = v.Uri;
            shareLinkTask.Message = "You may find this interesting.";

            shareLinkTask.Show();
        }
    }
}
